﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SU.Center.Infa
{
    public class ApiResult
    {
        public bool IsSuc { get; set; }
        public string Msg { get; set; }
        public object? Data { get; set; }
        public ApiEnumCode Code { get; set; }

        public ApiResult(bool isSuc, string msg, object? data, ApiEnumCode code)
        {
            IsSuc = isSuc;
            Msg = msg;
            Data = data;
            Code = code;
        }

        /// <summary>
        /// 成功信息
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static ApiResult Ok(object? data = null)
        {
            return new ApiResult(true, "操作成功", data, ApiEnumCode.Success);
        }

        /// <summary>
        /// 错误信息
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static ApiResult Error(string msg = "操作失败")
        {
            return new ApiResult(false, msg, null, ApiEnumCode.Error);
        }
    }

    public enum ApiEnumCode
    {
        Success = 200,
        Error = 500,
    }

}